package com.eternal.start;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.facade.callback.NavCallback;
import com.alibaba.android.arouter.launcher.ARouter;
import com.eternal.base.router.RouterActivityPath;

/**
 * @author Administrator
 */
@Route(path = RouterActivityPath.Start.PAGE_START)
public class StartActivity extends AppCompatActivity {
    private static final int DURATION=4000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if((getIntent().getFlags()&Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)!=0){
            finish();
            return;
        }
        setContentView(R.layout.activity_start);
        start();
    }

    private void start(){
        ObjectAnimator animator=ObjectAnimator.ofFloat(findViewById(R.id.layout_logo), "alpha", 0, 1);
        animator.setDuration(DURATION);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                ARouter.getInstance().build(RouterActivityPath.Main.PAGE_MAIN)
                        .navigation(StartActivity.this, new NavCallback() {
                            @Override
                            public void onArrival(Postcard postcard) {
                                finish();
                            }
                        });
            }
        });
        animator.start();
    }
}
